package com.bdsys.common.dao;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

public abstract class BasicDaoAbstract extends JdbcDaoSupport {
	
	private Map<String, String> map = new HashMap<String, String>();

	public BasicDaoAbstract(String sqlFileName){
		
		try {
			InputStream in = getClass().getClassLoader().getResourceAsStream(File.separator + "sql" + File.separator + sqlFileName + ".sql");
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			
			String str = null;
			StringBuilder sb = new StringBuilder();
			
			if (br != null){
				while((str = br.readLine()) != null){
					sb.append(str);
				}
				
				String[] array = sb.toString().split("#");
				for(String sql : array){
					String[] sqlArray = sql.split(":");
					if(sqlArray.length >= 2){
						map.put(sqlArray[0], sqlArray[1]);
					}
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String getSql(String sql){
		return map.get(sql);
	}

}
